package com.my.code.ftype;

import com.alibaba.fastjson.JSON;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 父类泛型，子类继承获取泛型的真实类型
 *
 * @param <T>
 */
public abstract class AbstractQueue<T> {

    protected Type clazz;

    public AbstractQueue() {
        Type genericSuperclass = getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
        this.clazz = params[0];
    }

    public T get() {
        String s = "{}";
        return JSON.parseObject(s, clazz);
    }

}
